﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Cinemax.DTO;
using System.Data.SqlClient;
namespace Cinemax.DAO
{
    public class PhimDAO
    {
        static rapphimDataContext data = new rapphimDataContext();
        public static List<PhimDTO> getAllFilm()
        {
            List<PhimDTO> lstFilms = new List<PhimDTO>();
            List<SP_GETALLFILMResult> allFilms = new List<SP_GETALLFILMResult>();
            allFilms = data.SP_GETALLFILM().ToList();

            foreach (SP_GETALLFILMResult item in allFilms)
            {
                PhimDTO film = new PhimDTO(item);
                lstFilms.Add(film);
            }

            return lstFilms;
        }

        public static List<PhimDTO> getAllFilmShowing()
        {
            List<PhimDTO> lstFilms = new List<PhimDTO>();
            List<SP_GETALLFILMSHOWINGResult> allFilms = new List<SP_GETALLFILMSHOWINGResult>();
            allFilms = data.SP_GETALLFILMSHOWING().ToList();

            foreach (SP_GETALLFILMSHOWINGResult item in allFilms)
            {
                PhimDTO film = new PhimDTO(item);
                lstFilms.Add(film);
            }

            return lstFilms;
        }

        public static List<PhimDTO> getAllFilmShowed()
        {
            List<PhimDTO> lstFilms = new List<PhimDTO>();
            List<SP_GETALLFILMSHOWEDResult> allFilms = new List<SP_GETALLFILMSHOWEDResult>();
            allFilms = data.SP_GETALLFILMSHOWED().ToList();

            foreach (SP_GETALLFILMSHOWEDResult item in allFilms)
            {
                PhimDTO film = new PhimDTO(item);
                lstFilms.Add(film);
            }

            return lstFilms;
        }

        public static List<PhimDTO> getAllFilmCommingSoon()
        {
            List<PhimDTO> lstFilms = new List<PhimDTO>();
            List<SP_GETALLFILMCOMMINGSOONResult> allFilms = new List<SP_GETALLFILMCOMMINGSOONResult>();
            allFilms = data.SP_GETALLFILMCOMMINGSOON().ToList();

            foreach (SP_GETALLFILMCOMMINGSOONResult item in allFilms)
            {
                PhimDTO film = new PhimDTO(item);
                lstFilms.Add(film);
            }

            return lstFilms;
        }

        public static PhimDTO getPhimByID(int id)
        {
            SP_GETPHIMBYIDResult p = new SP_GETPHIMBYIDResult();
            p = data.SP_GETPHIMBYID(id).ElementAt(0);
            PhimDTO phim = new PhimDTO(p);
            return phim;
        }
    }
}